#ifndef DELEGATE_H
#define DELEGATE_H

#include "delegate_global.h"
#include "../login1/login.h"
#include "../login1/loginstatus.h"
#include <QDialog>
#include <QButtonGroup>
#include <qabstractitemdelegate.h>
#include <QObject>
#include "mountdelegate.h"
#include "../CommunicateDelegate/hmicommunicate.h"


class CommunicateNormalDelegate;
class FtpDelegate;

class DELEGATESHARED_EXPORT Delegate : public QObject
{
    Q_OBJECT

public:
    Delegate(CommunicateNormalDelegate *communicateNormalIn,QString versionIn
             ,GlobalData *globalDataIn,GlobalData *ioDataIn,Login *loginViewIn,QObject* parent=0);
    ~Delegate();



    /**
     * @brief changeLoginViewMember 示教器ＩＰ设置
     */
    void changeLoginViewMember(QString ip);

    /**
     * @brief initConnect           初始化槽链接
     */
    void initConnect();

    /**
     * @brief writeIniCtrlIP        若登录成功,保存控制器IP 登录的记录
     */
    void writeIniCtrlIP(QString ip, QString port, int account, QString password, QString lang);
    /**
     * @brief readIniCtrlIP         读文件获取控制器IP
     */
    void readIniCtrlIP();
    int getShowStyle();
    /**
     * @brief initHmiNetwork        设置hmi net
     */
    void initHmiNetwork(QString ip,QString gateway,QString dns);
    /**
     * @brief initLanguage          设置语言 显示
     * @param lang
     */
    void initLanguage(int lang);
    /**
     * @brief pingTest              若登录失败,检查失败的类型
     * @return
     */
    bool pingTest(QString ip,int port);

    /**
     * @brief setShowInitialLanguage　设置HMI启动时语言显示
     * @param language　启动时的语言
     */
    void setShowInitialLanguage(int language);

signals:
    void controllerLoginSignal(QVector<int> controllerIpAddress,QVector<int> hmiIpAddress,
                               QString port,QString passwardString,int selectedAccount);

    void controllerLanguageChangedSignal(int selectedLanguage);
    /**
     * @brief msgBoxSignal                  通知 打开消息框
     */
    void msgBoxSignal(int type,QString title,QString text);
    void loginControllerSucess_signal();
    void msgBoxCloseSignal();

    /**
     * @brief callTmpInfoUpdate
     * @param serverIP
     */
    void callTmpInfoUpdate(QString serverIP);//通知 通信类 跟新用户数据

    /**
     * @brief tryToConnect
     */
    void tryToConnect_signal(QString hmiVersionInfo);

    /**
     * @brief tryToFindIP
     */
    void tryToFindIP();
    void stopFindIP();
    void logInSucessSignal();
    void mountFileSignal(QStringList list,QString mountPath);
    void signal_hmi_ip_port(QString ip,int port);

    /**
     * @brief midDelegateUpdateMountSignal  通知 中部策略 更新mount
     */
//    void midDelegateUpdateMountSignal();

    /**
     * @brief setLanguageSignal             设置语言信号(发送mainWindow和Comm)
     * @param lang
     */
    void setLanguageSignal(int lang);

    /**
     * @brief setEditLanguageSignal         设置编辑界面的语言
     * @param lang
     */
    void setEditLanguageSignal(int lang);

    /**
     * @brief loginToTfp  登录FTP
     */
    void loginToFtp(QString ctrlIp, int port, QString userName, QString userPasswd);

public slots:   
    void controllerLoginSlot(QVector<int> controllerIpAddress, QVector<int> hmiIpAddress, QString port, QString passwardString, int selectedAccount);

    /**
     * @brief hmiIpSettingSlot                  修改HMI IP
     */
    void hmiIpSettingSlot();
    void hmiIpSettingSlot(QString ip);

    /**
     * @brief loginErrorInformationSlot         扫描页面 选择IP后 重新登录
     * @param getIP
     */
    void loginErrorInformationSlot(QString controllerIp);

    /**
     * @brief scanControllerIpSlot              扫描IP
     */
    void scanControllerIpSlot();

    /**
     * @brief clearFindTimerSlot                扫描页面关闭时,关闭定时器
     */
    void clearFindTimerSlot();

    void loginGetConfigFileFinished();

    /**
     * @brief loginStatus                       FTP登录状态
     * @param loginStatus
     * @param message
     */
    void loginStatusSlot(bool loginResult, QString message);

    void connectToHostSlot(bool result, QString message);


public slots:
    void recvConnectResult(int result,  QString note);

    void findIpResultSlot(QVector<QString> findIP);

    /**
     * @brief changeLanguageSlot　修改界面语言槽函数
     * @param language
     */
    void changeLanguageSlot(int language);

public:
    MountDelegate *mountDelegate;

private:
    GlobalData *globalData;
    GlobalData *ioData;
    Login *loginView;
//    LoginStatus *loginStatus;
//    IpSetDialog *ipSetDialog;

    QThread mountThread;

    FtpDelegate *ftpDelegate;

    /**
     * @brief mountPath             获取需要挂载的地址
     */
    QString mountPath;

    /**************************************************
     *修改人：        hualei
     *修改日期：   2018-08-21
     * 修改说明: 添加 FTP 服务所需参数
     *
     * ***********************************************/
    /**
     * @brief isUseFtp          ture: FTP服务   false: NFS服务
     */
    bool isUseFtp;

    /**
     * @brief FtpUserName       登录FTP服务器时使用的“用户名”
     */
    QString ftpUserName;

    /**
     * @brief FtpUserPasswd     FTP服务用户登录密码
     */
    QString ftpUserPasswd;

    /**
     * @brief ftpPort          ftp端口号
     */
    int ftpPort;

private:
    QTranslator translator;

    QString getIPhmi;

    QString controllerIp;

    QString hmiPort;

    QString ftpServerIp;
    QString version;

    //QThread mountThread;


};

#endif // DELEGATE_H
